package com.hmall.trade.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    // 定义交换机
    @Bean
    public Exchange tradeExchange() {
        return ExchangeBuilder
                .topicExchange("trade.topic")
                .durable(true)
                .build();
    }

    // 定义队列
    @Bean
    public Queue cartClearQueue() {
        return QueueBuilder
                .durable("cart.clear.queue")
                .build();
    }

    // 定义绑定关系
    @Bean
    public Binding cartClearBinding() {
        return BindingBuilder
                .bind(cartClearQueue())
                .to(tradeExchange())
                .with("order.create")
                .noargs();
    }



    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}

